package org.example.carsystem.controller;
import com.github.pagehelper.PageInfo;
import org.example.carsystem.domain.SysOperLog;
import org.example.carsystem.service.SysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/slog")
@CrossOrigin
public class SysOperLogController {
    @Autowired
    SysOperLogService sysOperLogService;
    @RequestMapping("/list")
    public Map<String,Object> list(@RequestBody SysOperLog sysOperLog, Integer pageNum, Integer pageSize){
        PageInfo<SysOperLog> info = sysOperLogService.selectAll(sysOperLog,pageNum, pageSize);
        HashMap<String, Object> map = new HashMap<>();
        map.put("info",info);
        map.put("code","200");
        return map;
    }
    @RequestMapping("/del")
    public Map<String,Object> del(List<Integer> list)throws Exception{
        HashMap<String, Object> map = new HashMap<>();
        try {
            sysOperLogService.del(list);
            map.put("code",200);
            map.put("msg","删除失败");
            return map;
        }catch (Exception e){
            e.printStackTrace();
            map.put("code",201);
            map.put("msg","删除成功");
            return map;
        }
    }
    @RequestMapping("/saveOrupdate")
    public Map<String,Object> saveOrupdate(@RequestBody SysOperLog sysOperLog){
        HashMap<String, Object> map = new HashMap<>();
        try {
            sysOperLogService.saveOrupdate(sysOperLog);
            map.put("code",200);
            map.put("msg",201);
            return map;
        }catch (Exception e){
            e.printStackTrace();
            map.put("code",200);
            map.put("msg",201);
            return map;
        }
    }
}
